from __future__ import unicode_literals
import requests
from bs4 import BeautifulSoup
import time
import json
import mgadapter

adapter=mgadapter.mgadapter()
ulist=[]
baseurl='https://www.looporn.com'
for i in range(1,11):
    time.sleep(2)
    url='https://www.looporn.com/'+str(i)+'?q=asians'
    r=requests.get(url,timeout=10)
    content=r.content
    soup=BeautifulSoup(content,'lxml')
    for item in soup.find('div',attrs={'class':'row text-center'}).find_all('a',attrs={'class':'imageLink'}):
        atag=baseurl+item['href']
        print(atag)
        ulist.append(atag)
        break
    break

while len(ulist)>0:
    print(str(len(ulist)))
    try:
        time.sleep(2)
        url=ulist.pop()
        r=requests.get(url,timeout=10)
        content=r.content
        soup=BeautifulSoup(content,'lxml')
        mp4url=soup.find('video',attrs={'class':'video-js vjs-default-skin vjs-fluid'}).find('source',attrs={'label':'720p'})['src']
        print(mp4url)
        adapter.add_str(mp4url)
        break
    except Exception as e:
        print(e)
        continue

# adapter.sub_mit()